#!/usr/bin/python3.7
# -*- coding: utf-8 -*-
# @Author  : cs
# @File    : 6.27.py
# @Software: PyCharm
class Empty(Exception):
    pass #占位语句
class ArrayStack:
    def __init__(self):
        self._data=[]
    def __len__(self):
        return len(self._data)
    def is_empty(self):
        return len(self._data)==0
    def push(self,e):
        self._data.append(e)
    def top(self):
        if self.is_empty():
            raise Empty("Stack is empty")
        return self._data[-1]
    def pop(self):
        if self.is_empty():
            raise Empty("Stack is empty")
        return self._data.pop()
class ArrayQueue:
    DEFAULT_CAPACITY=10
    def __init__(self):
        self._data=[None]*ArrayQueue.DEFAULT_CAPACITY
        self._size=0
        self._front=0
    def __len__(self):
        return self._size
    def is_empty(self):
        return self._size==0
    def first(self):
        if self.is_empty():
            raise Empty('Queue is empty')
        return self._data[self._front]
    def dequeue(self):
        if self.is_empty():
            raise Empty('Queue is empty')
        answer=self._data[self._front]
        self._data[self._front]=None
        self._front=(self._front+1)%len(self._data)
        self._size=self._size-1
        return answer
    def enqueue(self,e):
        if self._size==len(self._data):
            self._resize(2*len(self._data))
        avail=(self._front+self._size)%len(self._data)
        self._data[avail]=e
        self._size+=1
    def _resize(self,cap):
        old=self._data
        self._data=[None]*cap
        walk=self._front
        for k in range(self._size):
            self._data[k]=old[walk]
            walk=(1+walk)%len(old)
        self._front=0
#用Q（队列）扫描S（栈）来查看其中是否包含某一特定元素x，返回x在S中原来的位置
def find_num(S,Q,x):
    len=S.__len__()
    i=len
    flag=1
    while S.is_empty()!=True:
        e=S.pop()
        Q.enqueue(e)
        if e==x:
            flag=0
        if flag==1:
            i-=1
    return i
if __name__ == '__main__':
    S = ArrayStack()
    Q = ArrayQueue()
    S.push(6)
    S.push(7)
    S.push(8)
    S.push(9)
    S.push(10)
    i = find_num(S, Q, 9)
    print(i)

